package com.example.text3;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class ImageViewActivity extends AppCompatActivity {
    private Button buttonPrevious;
    private Button buttonNext;
    private ImageView imageViewFunny;
    private int[] imageIDArray = {
            R.drawable.funny_1, R.drawable.funny_2,
            R.drawable.funny_3, R.drawable.funny_4,
            R.drawable.funny_5, R.drawable.funny_6
    };
    private int imageIDArrayCurrentIndex = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_view);

        buttonPrevious = findViewById(R.id.button_previous);
        buttonNext = findViewById(R.id.button_next);
        imageViewFunny = findViewById(R.id.image_view_funny);

        buttonPrevious.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageIDArrayCurrentIndex--;
                if (imageIDArrayCurrentIndex < 0) {
                    imageIDArrayCurrentIndex = imageIDArray.length - 1;
                }
                imageViewFunny.setImageResource(imageIDArray[imageIDArrayCurrentIndex]);
            }
        });

        buttonNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageIDArrayCurrentIndex++;
                if (imageIDArrayCurrentIndex >= imageIDArray.length) {
                    imageIDArrayCurrentIndex = 0;
                }
                imageViewFunny.setImageResource(imageIDArray[imageIDArrayCurrentIndex]);
            }
        });
    }
}